﻿<UserControl xmlns:controlsToolkit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Toolkit"  x:Class="DemoNYTimes.NewswirePage"
    xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"  
    xmlns:my="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data"  
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:nyt="clr-namespace:NYTimes;assembly=NYTimesSilverlightKit"
    xmlns:nytd="clr-namespace:NYTimes.Data;assembly=NYTimesSilverlightKit"
    xmlns:nytvc="clr-namespace:NYTimes.ValueConverters;assembly=NYTimesSilverlightKit"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" FontFamily="Times New Roman" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480">
    <UserControl.Resources>
        <nyt:Newswire x:Key="Newswire" ResultsToGet="100"/>
        <nytvc:DateTimeConverter x:Key="DateTimeConverter"/>
        <DataTemplate x:Key="HeaderTemplate">
            <TextBlock Text="{Binding}" FontWeight="Bold" Margin="2"/>
        </DataTemplate>
        <Style x:Key="HeaderedItems" TargetType="controls:HeaderedItemsControl">
            <Setter Property="VerticalAlignment" Value="Top"/>
            <Setter Property="Margin" Value="2"/>
            <Setter Property="HeaderTemplate" Value="{StaticResource HeaderTemplate}"/>
        </Style>
        <ItemsPanelTemplate x:Key="WrapPanelTemplate">
            <controlsToolkit:WrapPanel/>    
        </ItemsPanelTemplate>
        <DataTemplate x:Key="MediaTemplate">
            <Grid>
                <StackPanel>
                    <Image Source="{Binding Path=Metadata.Image}" ToolTipService.ToolTip="{Binding Path=Copyright}" ImageFailed="OnImageFailed"/>
                    <TextBlock TextWrapping="Wrap" Text="{Binding Path=Caption}" MaxWidth="192"/>
                </StackPanel>
            </Grid>
        </DataTemplate>
        <Style x:Key="BorderStyle1" TargetType="Border">
        	<Setter Property="BorderThickness" Value="1,1,1,1"/>
        	<Setter Property="Margin" Value="2,2,2,2"/>
        	<Setter Property="CornerRadius" Value="4,4,4,4"/>
        	<Setter Property="BorderBrush" Value="#FF000000"/>
            <Setter Property="VerticalAlignment" Value="Top"/>
        </Style>
        <DataTemplate x:Key="RowDetailTemplate">
            <Border BorderBrush="Black" BorderThickness="1,0,1,1" CornerRadius="0,0,4,4">
            <StackPanel>
                    <StackPanel Orientation="Horizontal">
                        <TextBlock Margin="4"  TextWrapping="Wrap" HorizontalAlignment="Left" MaxWidth="500" Text="{Binding Path=Summary}"/>
                        <HyperlinkButton Margin="2" TargetName="_blank" NavigateUri="{Binding Path=Url}" Content="{Binding Path=Source}"/>
                        </StackPanel>
                <StackPanel Orientation="Horizontal">
                    <ListBox 
                    ItemsSource="{Binding Path=Media}" 
                    Margin="2" 
                    ItemsPanel="{StaticResource WrapPanelTemplate}"
                    ItemTemplate="{StaticResource MediaTemplate}"/>
                    <Border Height="Auto" Width="Auto" BorderThickness="1,1,1,1" BorderBrush="#FF000000" Style="{StaticResource BorderStyle1}">
                    	<controls:HeaderedItemsControl Header="Indexing Terms" ItemsSource="{Binding Path=IndexingTerms}" Style="{StaticResource HeaderedItems}" />
                    </Border>
                    <Border Style="{StaticResource BorderStyle1}">
                    	<controls:HeaderedItemsControl Header="Locations" ItemsSource="{Binding Path=Locations}" Style="{StaticResource HeaderedItems}"/>
                    </Border>
                    <Border Style="{StaticResource BorderStyle1}">
                    	<controls:HeaderedItemsControl Header="Organizations" ItemsSource="{Binding Path=Organizations}" Style="{StaticResource HeaderedItems}"/>
                    </Border>
                    <Border Style="{StaticResource BorderStyle1}">
                    	<controls:HeaderedItemsControl Header="People" ItemsSource="{Binding Path=People}" Style="{StaticResource HeaderedItems}"/>
                    </Border>
                    <Border Style="{StaticResource BorderStyle1}">
                    	<controls:HeaderedItemsControl Header="Terms" ItemsSource="{Binding Path=Terms}" Style="{StaticResource HeaderedItems}"/>
                    </Border>
                    <Border Style="{StaticResource BorderStyle1}">
                    	<controls:HeaderedItemsControl Header="Related Urls" ItemsSource="{Binding Path=RelatedUrls}" Style="{StaticResource HeaderedItems}">
                    		<controls:HeaderedItemsControl.ItemTemplate>
                    			<DataTemplate>
                    				<Grid>
                    					<HyperlinkButton Content="{Binding Path=SuggestedLinkText}" NavigateUri="{Binding Path=Url}" TargetName="_blank"/>
                    				</Grid>
                    			</DataTemplate>
                    		</controls:HeaderedItemsControl.ItemTemplate>
                    	</controls:HeaderedItemsControl>
                    </Border>
                </StackPanel>
            </StackPanel>
                </Border>
        </DataTemplate>
    </UserControl.Resources>
    <Grid x:Name="LayoutRoot" Margin="2" Background="#FFFFFFFF">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition/>
        </Grid.RowDefinitions>
        <StackPanel Orientation="Horizontal">
            <RadioButton Margin="2" GroupName="TimePeriod" Content="All available recent items" Tag="Recent" Checked="OnTimePeriodChecked"/>
            <RadioButton Margin="2" GroupName="TimePeriod" Content="Items published in the last 24 hours" Tag="Last24Hours" Checked="OnTimePeriodChecked"/>
            <TextBlock Margin="2" Text="Items: " />
            <TextBlock Margin="2" Text="{Binding Path=Results.Count, Source={StaticResource Newswire}}"/>
        </StackPanel>
        <my:DataGrid 
            FontSize="14"
            Grid.Row="1"
            ItemsSource="{Binding Path=Results, Source={StaticResource Newswire}}" 
            IsReadOnly="True" AutoGenerateColumns="False"
            RowDetailsTemplate="{StaticResource RowDetailTemplate}">
            <my:DataGrid.Columns>
                <my:DataGridTemplateColumn Header="Headline">
                    <my:DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <StackPanel Margin="4">
                                <TextBlock Text="{Binding Path=Headline}" FontWeight="Bold"/>
                                <TextBlock Text="{Binding Path=SubHeadline}"/>
                                <StackPanel Orientation="Horizontal">
                                    <TextBlock Text="{Binding Path=Byline}"/>    
                                    <TextBlock Text="{Binding Path=Kicker}"/>
                                </StackPanel>
                            </StackPanel>
                        </DataTemplate>
                    </my:DataGridTemplateColumn.CellTemplate>
                </my:DataGridTemplateColumn>
                <my:DataGridTextColumn Header="Section" Binding="{Binding Path=Section}"/>
                <my:DataGridTextColumn Header="Blog Name" Binding="{Binding Path=BlogName}"/>
                <my:DataGridTextColumn Header="Published" Binding="{Binding Converter={StaticResource DateTimeConverter}, ConverterParameter=d, Path=PubDate}"/>
                <my:DataGridTextColumn Header="Type" Binding="{Binding Path=ItemType}"/>
                <my:DataGridTextColumn Header="Subtype" Binding="{Binding Path=Subtype}"/>
            </my:DataGrid.Columns>
        </my:DataGrid>
    </Grid>
</UserControl>
